#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
开放商户 - 商户信息变更功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.change.change_service import ChangeService
from jlpay.model.openmerch.change.merch_info_change import MerchInfoChangeRequest
from jlpay.model.openmerch.change.merch_info_dto import (
    MerchBaseInfoDto, MerchBusinessInfoDto, 
    MerchIdentificationInfoDto, MerchSettleInfoDto
)


class MerchInfoChangeExample(BaseExample):
    """商户信息变更示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.change.merch_info")
        self.change_service = ChangeService(self.config)
    
    def build_merch_info_change_request(self):
        """构建商户信息变更请求"""
        request = MerchInfoChangeRequest()
        
        # 构建商户基础信息
        base_info = MerchBaseInfoDto()
        base_info.set_apply_id("b8659ea518d14c99b78b5ad000a4155a")
        base_info.set_product_type("01")
        
        # 构建商户业务信息
        business_info = MerchBusinessInfoDto()
        business_info.set_merch_no("849584358140108")  # 使用cursor中的商户号
        
        # 构建商户身份信息
        identification_info = MerchIdentificationInfoDto()
        identification_info.set_id_card_name("张三")                    # 经营者/法人姓名
        identification_info.set_id_card_english_name("Zhang San")      # 经营者/法人英文名称
        identification_info.set_id_card_no("445221199705024935")      # 经营者/法人身份证件号码
        identification_info.set_legal_person_phone("13800138000")     # 经营者/法人手机号码
        identification_info.set_license_name("北京科技有限公司")        # 商户法定名称
        identification_info.set_business_scope("软件开发、技术服务")    # 经营范围
        identification_info.set_license_address("北京市朝阳区xxx街道")  # 注册地址
        identification_info.set_license_pic("group1/M00/5E/DB/rBQFm2cRyWGAUF_zAAS9l9WA_pE1351477")
        
        # 构建结算信息
        settle_info = MerchSettleInfoDto()
        
        # 设置请求参数
        request.set_base_info(base_info)
        request.set_business_info(business_info)
        request.set_identification_info(identification_info)
        
        return request
    
    def demo(self):
        """执行商户信息变更示例"""
        self.logger.info("开始执行商户信息变更示例")
        
        # 构建请求
        request = self.build_merch_info_change_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.change_service.change_merch_info,
            "商户信息变更",
            request
        )
        
        self.logger.info("商户信息变更示例执行完毕")


if __name__ == "__main__":
    example = MerchInfoChangeExample()
    example.logger.info("=" * 50)
    example.logger.info("===== 商户信息变更示例 开始 =====")
    example.logger.info("=" * 50)
    
    example.demo()
    
    example.logger.info("=" * 50)
    example.logger.info("===== 商户信息变更示例执行完毕 =====")
    example.logger.info("=" * 50) 